package live.common;

import java.io.Serializable;

public class Page implements Serializable {
	private static final long serialVersionUID = -1126366533333194979L;
	private int pageIndex; // 当前页码
	private int recordCount; // 总记录数
	private int pageSize; // 页条数
	private int totalPage; // 总页数

	public int getTotalPage() {
		totalPage = (int) Math.ceil(recordCount*1.0/ pageSize);
		
//		if (recordCount % pageSize > 0) {
//			totalPage += 1;
//		}
//		if (recordCount < pageSize) {
//			totalPage = 1;
//		}
		return totalPage!=0?totalPage:1;
	}

	public int getPageIndex() {
		if (pageIndex < 1) {
			pageIndex = 1;
		}
		return pageIndex;
	}

	public void setPageIndex(int pageIndex) {
		this.pageIndex = pageIndex;
	}

	public int getRecordCount() {
		return recordCount;
	}

	public void setRecordCount(int recordCount) {
		this.recordCount = recordCount;
	}

	public int getPageSize() {
		if (pageSize == 0) {
			pageSize = 15;
		}
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public Page() {
	}

	public Page(int pageIndex, int recordCount,int totalPage, int pageSize) {
		// TODO Auto-generated constructor stub
		this.pageIndex = pageIndex;
		this.recordCount = recordCount;
		this.pageSize = pageSize;
		this.totalPage = totalPage;
	}
}
